import 'package:get/get.dart';

import '../../../service/xin_he_reqest.dart';
import '../../../utils/xin_he_storage.dart';
import '../../../utils/xin_he_toast.dart';
import '../xin_he_mine_cloud_cha_zi/xin_he_assets_account_list_item_entity.dart';
import '../xin_he_mine_cloud_cha_zi/xin_he_assets_acount_model.dart';
import 'xin_he_mine_left_money_state.dart';

class XinHeMineLeftMoneyLogic extends GetxController {
  final XinHeMineLeftMoneyState state = XinHeMineLeftMoneyState();
  Rx<XinHeAssetsAccountModel> assetsModel = XinHeAssetsAccountModel().obs;
  RxList dataList = [].obs;


  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();

    requestAssetAcount();

    requestAssetDetailByUser();
  }

  requestAssetAcount() async {

    var userId = await XinHeLocalStorage.get(XinHeStorage.userId);
    Map<String,dynamic> ss = {
      'userId':userId,
      'assetType': 'RMB'
    };

    XinHeRequestDataResult result = await XinHeHttpRequestData.requestUniversalPost(url: '/assetDetailCount/queryAssetCount',params: ss,isPost: false);
    if(!result.result || result.data['code'] != 0) {
      XinHeToast.center(result.data['message']);
      return ;
    }
    Map<String, dynamic> json = result.data['data'];
    XinHeAssetsAccountModel model = XinHeAssetsAccountModel.fromJson(json);
    assetsModel.value = model;
  }


  requestAssetDetailByUser() async {

    var userId = await XinHeLocalStorage.get(XinHeStorage.userId);
    Map<String,dynamic> ss = {
      'userId':userId,
      'assetType': 'RMB'
    };

    XinHeRequestDataResult result = await XinHeHttpRequestData.requestUniversalPost(url: '/assetDetailCount/queryAssetDetailByUser',params: ss,isPost: false);
    if(!result.result || result.data['code'] != 0) {
      XinHeToast.center(result.data['message']);
      return ;
    }
    List list = result.data['data']??[];
    List modelArr = [];
    if(list.isNotEmpty) {
      for(var e in list) {
        XinHeAssetsAccountListItemEntity model = XinHeAssetsAccountListItemEntity.fromJson(e);
        modelArr.add(model);
      }
      dataList.value = modelArr;
    }
  }

}
